package alan.mybatisPlusDb.module.order.controller;


import alan.mybatisPlusDb.module.order.entity.TOrder;
import alan.mybatisPlusDb.module.order.service.ITOrderService;
import alan.mybatisPlusDb.module.order.service.ITestTOrderService;
import alan.mybatisPlusDb.module.order.service.impl.TOrderServiceImpl;
import alan.mybatisPlusDb.module.order.service.impl.TestTOrderServiceImpl;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author alan
 * @since 2021-03-03
 */
@RestController
@RequestMapping("/order/t-order")
public class TOrderController {

    @Autowired
    TOrderServiceImpl tOrderService;

    @Autowired
    ITestTOrderService ITestTOrderService;

    @PostMapping("save2Share")
    public String save2Share(TOrder tOrder){
        boolean save = tOrderService.save2Share(tOrder);
        return save + "";
    }

    @PostMapping("save2Master")
    public String save2Master(TOrder tOrder) {
        boolean save = tOrderService.save2Master(tOrder);
        return save + "";
    }

    @GetMapping("getByOrderIdWithShare")
    public String getByOrderIdWithShare(Long id) {
        List<TOrder> tOrder = tOrderService.getByOrderIdWithShare(id);
        return JSON.toJSONString(tOrder);
    }

    @GetMapping("getByOrderIdWithMaster")
    public String getByOrderIdWithMaster(Long id) {
        List<TOrder> tOrder = tOrderService.getByOrderIdWithMaster(id);
        return JSON.toJSONString(tOrder);
    }


    @GetMapping("getByOrderIdWithShareV2")
    public String getByOrderIdWithShareV2(Long id) {
        List<TOrder> tOrder = ITestTOrderService.getByOrderIdWithShare(id);
        return JSON.toJSONString(tOrder);
    }

    @GetMapping("getByOrderIdWithMasterV2")
    public String getByOrderIdWithMasterV2(Long id) {
        List<TOrder> tOrder = ITestTOrderService.getByOrderIdWithMaster(id);
        return JSON.toJSONString(tOrder);
    }

    @GetMapping("getByOrderIdAndUserIdWithShareV2")
    public String getByOrderIdAndUserIdWithShareV2(Long orderId,Long userId) {
        List<TOrder> tOrder = ITestTOrderService.getByOrderIdAndUserIdWithShare(orderId,userId);
        return JSON.toJSONString(tOrder);
    }

}

